<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/9/16
 * Time: 12:33
 */

namespace Home\Controller;

use Common\Controller\BaseHomeController;

class ArchivesController extends BaseHomeController
{

    public function index()
    {
        $where  = array('is_del' => 0);
        $fields = "*,FROM_UNIXTIME(`create_time`,'%Y') AS recordtime";
        $order  = "create_time desc";
        $articles = D('Article')->getAllData($where, $fields, $order);

        $data = array();
        $i = 0;
        foreach ($articles as $key => $value) {
            $num = $value['recordtime'];
            $data[$i]['year'] = $num;
            $data[$i]['value'][] = $value;
            if ($articles[$key + 1]['recordtime'] != $num) {
                $i++;
            }
        }
        $this->assign('data', $data);
        $this->display();
    }

} 